<?php
function dpa_unlock_achievement_send_notification( $user_id, $achievement_name ) {
		global $bp;

		if ( 'no' == get_usermeta( (int) $user_id, 'notification_dpa_unlock_achievement' ) )
			return false;

		$nice_name = dpa_get( 'nice_name', array( array( 'type' => 's', 'key' => 'short_name', 'value' => $achievement_name ) ), 1 );
		$userdata = get_userdata( $user_id );
		$profile_link = site_url( BP_MEMBERS_SLUG . '/' . $userdata->user_login . '/' . $bp->achievements->slug );
		$settings_link = site_url( BP_MEMBERS_SLUG . '/' . $userdata->user_login . '/settings/notifications' );
		$to = $userdata->user_email;
		$subject = __( '[' . get_blog_option( 1, 'blogname' ) . '] Achievement unlocked', 'dp-achievements' );

		$message = sprintf( __( '
	You have unlocked an achievement: %s

	To review this and see all of your achievements, go to %s

	---------------------
	', 'dp-achievements' ), $nice_name, $profile_link );

		$message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'dp-achievements' ), $settings_link );

	wp_mail( apply_filters( 'dpa_unlock_achievement_email_to', $to ), apply_filters( 'dpa_unlock_achievement_email_subject', $subject ), apply_filters( 'dpa_unlock_achievement_email_message', $message ) );
}
add_action( 'dpa_unlock_achievement_notification', 'dpa_unlock_achievement_send_notification', 10, 2 );
?>